import 'package:flutter/material.dart';
import 'package:flutter_app_05/page/calpage/pageviewpage.dart';
import 'package:flutter_app_05/page/calpage/single_screen.dart';
import 'package:flutter_app_05/page/index.dart';
import 'package:flutter_app_05/utils/MyTheme.dart';
import 'package:flutter_app_05/utils/ScreenAdapter.dart';
import 'package:provider/provider.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'action/states/dark_states.dart';
import 'page/calpage/mypageview.dart';
import 'widget/bottom_navigation_widget.dart';

void main() {
  runApp(
      MultiProvider(providers: [
        ChangeNotifierProvider(create: (context) => DartState())
      ],
        child: MyApp(),
      )
  );
}

class MyApp extends StatefulWidget {
  // This widget is the root of your application.
  @override
  _MyHomePageState createState() => _MyHomePageState();


}

class _MyHomePageState extends State<MyApp> {

  int into = 0;

  @override
  Widget build(BuildContext context) {
    Future<bool> isCanInto = getInto() as Future<bool>;
    isCanInto.then((value) =>into = value?1:2);
    return Consumer<DartState>(
        builder: (context, categoryState, child) {
          categoryState.initMode().then((value) {
            setState(() {

            });
          });
          return MaterialApp(
            debugShowCheckedModeBanner: false,
            title: 'Flutter Demo',
            theme: ThemeData(
              primarySwatch: Colors.green,
              backgroundColor: MyTheme(context).getColor("tab_bg"),
              brightness: MyTheme(context).getCurrentTheme() == 1 ? Brightness
                  .light : Brightness.dark,
              // backgroundColor:
            ),
            // home: BottomNavigationWidget(),
            home: into==1?BottomNavigationWidget():VviewPage(),
            routes: <String, WidgetBuilder > {
              '/BottomNavigationWidget': (context) => BottomNavigationWidget(),
              '/VviewPage': (context) => VviewPage()
            },
          );
        }
    );
  }

  Future<bool> getInto() async {
    bool isCanInto;
    SharedPreferences prefs = await SharedPreferences.getInstance();
    isCanInto = await prefs.getBool("isCanInto");
    return isCanInto;
  }
}